package com.example.design.pattern.behavior

/**
 *Create by Fanketly on 2022/9/1
 *Gitee:https://gitee.com/fanketly
 *desc:目的：解决稳定的数据结构和易变的操作耦合问题
优点：符合单一职责，易扩展
缺点：违反了迪米特原则、依赖倒置原则，依赖了具体实现类，不是依赖抽象
 */
fun main() {
    val use2 = Use2()
    val imageSystem = ImageSystem()
    val cameraSystem = CameraSystem()
    imageSystem.accept(use2)
    cameraSystem.accept(use2)
}

class Use2 : Visitor {
    override fun visitor(cameraSystem: CameraSystem) {
        cameraSystem.takePicture()
    }

    override fun visitor(imageSystem: ImageSystem) {
        imageSystem.selectPhoto()
    }
}

interface Action2 {
    fun accept(visitor: Visitor)
}

class CameraSystem : Action2 {
    override fun accept(visitor: Visitor) {
        visitor.visitor(this)
    }

    fun takePicture() {

    }
}

class ImageSystem : Action2 {
    override fun accept(visitor: Visitor) {
        visitor.visitor(this)
    }

    fun selectPhoto() {

    }
}

interface Visitor {
    fun visitor(cameraSystem: CameraSystem)
    fun visitor(imageSystem: ImageSystem)
}